<!--
 * @Author: your name
 * @Date: 2021-11-10 15:27:50
 * @LastEditTime: 2021-11-22 16:23:50
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \li-yuwei\admin\src\views\home\workbench\index.vue
-->
<template>
  <div class="workbench">
    <div class="identity-box">
      <h1>你好，{{ name }}</h1>
      <div>您的角色：{{ identity }}</div>
    </div>
    <!-- 面板导航 -->
    <div class="panel-nav-box">
      <div class="panel-text">面板导航</div>
      <div class="draw-box">
        <div id="chart" style="width: 85%; height: 85%" ref="chart"></div>
      </div>
    </div>
    <!-- 快速导航 -->
    <el-card class="box-card" shadow="never">
      <div slot="header" class="clearfix">
        <span>卡片名称</span>
      </div>
      <div class="card-item">
        <div
          v-for="(item, index) in speedNav"
          :key="index"
          class="text item"
          @click="gotoUrl(item.path)"
        >
          {{ item.text }}
        </div>
      </div>
    </el-card>
    <el-card class="new-article-box">
      <div slot="header" class="clearfix">
        <span>最新文章</span>
        <span
          style="float: right; padding: 3px 0; cursor: pointer"
          @click="
            () => {
              $router.push('/articleAdmin/allAdmin');
            }
          "
          >全部文章</span
        >
      </div>
      <div class="main-box">
        <div
          style="width: 33%; max-width: 33%"
          v-for="item in newArticle"
          :key="item.id"
          @click="toArticleDetail(item.id)"
        >
          <a-card hoverable style="width: 100%; text-align: center">
            <template v-if="item.cover">
              <img
                :src="item.cover"
                slot="cover"
                :alt="item.title"
                style="width: 100%; height: 120px"
              />
            </template>
            <img
              v-else
              slot="cover"
              alt="example"
              :src="NoImg"
              style="width: 100%; height: 120px"
            />
            <a-card-meta :title="item.title"></a-card-meta>
          </a-card>
        </div>
      </div>
    </el-card>
  </div>
</template>
<script>
import drawOption from "../../../draw/workbench";
import { speedNav } from "../../../data/workbench";
import NoImg from "../../../assets/暂无.gif";
import api from "@/api";
export default {
  computed: {},
  data() {
    return {
      identity: "", //身份
      name: "", //名字
      drawOption, //echarts数据
      speedNav, //快速导航数据
      newArticle: [],
      NoImg,
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    //echarts初始化
    init() {
      //2.初始化
      this.chart = this.$Echarts.init(this.$refs.chart);
      this.chart.setOption(drawOption);
    },
    //跳转方法
    gotoUrl(path) {
      this.$router.push(path);
    },
    //获取最新文章数据
    async getNewArticle() {
      const res = await api.getNewArticle();
      this.newArticle = res.data;
    },
    //详情
    toArticleDetail(id) {
      this.$router.push(`/article/${id}`);
    },
  },
  created() {
    //获取最新文章数据
    this.getNewArticle();
    //获取用户信息
    const userData = JSON.parse(window.localStorage.getItem("userData"));
    this.identity = userData.identity;
    this.name = userData.nickname;
  },
};
</script>

<style lang="scss" scoped>
.workbench::-webkit-scrollbar {
  width: 0 !important;
}
.workbench {
  width: 100%;
  height: 100%;
  overflow-y: scroll;
}
.identity-box {
  width: 100%;
  height: 100px;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 99;
  h1 {
    font-size: 38px;
    margin-bottom: 12px;
  }
}
.panel-nav-box {
  width: 95%;
  margin: 0 auto;
  background-color: #fff;
  margin-top: 20px;
  height: 350px;
  display: flex;
  flex-direction: column;
  .panel-text {
    padding: 20px;
    border-bottom: 1px solid rgb(235, 233, 233);
  }
  .draw-box {
    height: 290px;
  }
}
.box-card {
  width: 95%;
  margin: 0 auto;
  margin-top: 15px;
  margin-bottom: 15px;
}
.card-item {
  display: flex;
  justify-content: space-around;
  div {
    cursor: pointer;
  }
}
.new-article-box {
  width: 95%;
  margin: 0 auto;
  margin-top: 15px;
  margin-bottom: 15px;
}
.main-box {
  display: flex;
  flex-wrap: wrap;
}
</style>
